package com.cenluan.beetl;

import java.io.IOException;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.resource.FileResourceLoader;
import org.beetl.ext.jfinal.BeetlRender;

import com.jfinal.kit.PathKit;
import com.jfinal.render.IMainRenderFactory;
import com.jfinal.render.Render;

public class BeetlRenderFactory implements IMainRenderFactory {
	public static String viewExtension = ".html";
	public static GroupTemplate GT = null;

	public BeetlRenderFactory() {
		FileResourceLoader loader = new FileResourceLoader(
				PathKit.getWebRootPath() + "/WEB-INF/beetl");
		try {
			GT = new GroupTemplate(loader, Configuration.defaultConfiguration());
		} catch (IOException e) {
			throw new RuntimeException("加载GroupTemplate失败", e);
		}
	}

	public Render getRender(String view) {
		return new BeetlRender(GT, view);
	}

	public String getViewExtension() {
		return viewExtension;
	}

}
